package com.hshoesmall.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hshoesmall.demo.common.api.ApiResult;
import com.hshoesmall.demo.model.dto.ShoesOrderAddDTO;
import com.hshoesmall.demo.model.dto.ShoesOrderShoesDTO;
import com.hshoesmall.demo.model.entity.ShoesOrder;
import com.hshoesmall.demo.model.entity.ShoesOrderShoes;
import com.hshoesmall.demo.service.ShoesOrderService;
import com.hshoesmall.demo.service.ShoesOrderShoesService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/orders")
public class ShoesOrderController  {

    @Resource
    ShoesOrderService shoesOrderService;


    @GetMapping("/list/{ouid}")
    public ApiResult<List<ShoesOrder>> getShoesListbyOuid( @PathVariable("ouid")  Integer ouid ){
        List<ShoesOrder> orderlist = shoesOrderService.list(new
                LambdaQueryWrapper<ShoesOrder>().eq(ShoesOrder::getOuid,ouid));
        return ApiResult.success(orderlist);

    }

    @GetMapping("/orerDetail/{oid}")
    public ApiResult<List<ShoesOrder>> getOrderDetailbyOuid( @PathVariable("oid")  Integer oid ){
        List<ShoesOrder> orderDetail = shoesOrderService.list(new
                LambdaQueryWrapper<ShoesOrder>().eq(ShoesOrder::getOid,oid));
        return ApiResult.success(orderDetail);

    }

    @PostMapping("/addOrder")
    public ApiResult<Map<String, Object>> addOrder(@RequestBody ShoesOrderAddDTO dto) {
        ShoesOrder order = shoesOrderService.addOrder(dto);

        if (ObjectUtils.isEmpty(order)) {
            return ApiResult.failed("订单提交失败");
        }
        Map<String, Object> map = new HashMap<>(16);
        map.put("order", order);
        return ApiResult.success(map);
    }



}